********************************************************************************
*Project:  	Swiss Trade During the Covid-19 Pandemic: An Early Appraisal	
*Authors:	KB, SL, VP, PW												
*This File: Figure 6
*Version: 	vFinal						
*Date: 		2020-09-01					
********************************************************************************


********************************************************************************
*PMI
********************************************************************************

import delimited "${root}\data\PMI_KS_Data\pmi_dta_raw.csv", clear 

rename *manpm country_*
rename usmanmepm country_us

split time, parse("-")
destring time1, gen(year)
destring time2, gen(month)
destring time3, gen(day)

drop time*

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date

foreach var of varlist country_at-country_vn {
	sum `var'
	gen `var'_std=(`var'-r(mean))/r(sd)
}

global TOP10 "country_de_std country_fr_std country_it_std country_at_std country_es_std country_gb_std country_us_std country_jp_std country_nl_std country_cn_std"

egen mean_top10=rowmean(${TOP10})
egen med_top10=rowmedian(${TOP10})
egen min_top10=rowmin(${TOP10})
egen max_top10=rowmax(${TOP10})

order date

twoway 	///
(line country_de_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin)) 	///
(line country_fr_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_it_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_at_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_es_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_us_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin)) ///
(line country_nl_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_jp_std date if date>=td(1jan2020) & date<td(1aug2020), lpattern(shortdash) lcolor(gs8) lwidth(medium))		///
(line country_cn_std date if date>=td(1jan2020) & date<td(1aug2020), lpattern(dash) lcolor(gs4) lwidth(medium)) 	///
(line country_gb_std date if date>=td(1jan2020) & date<td(1aug2020), lpattern(longdash) lcolor(gs2) lwidth(medium))	///
(line country_ch_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(maroon) lwidth(medium)),	///
ytitle("Standardized Purchasing Manager Index")  yscale(range (-5 3))  ///
ylabel(-5(1)3,nogrid) xlabel(#7)  xtitle("")									///
tline(16mar2020, lcolor(maroon) lwidth(medium)) 								///
yline(0, lcolor(gs0) lwidth(vthin)) 											///	
ttext(-5 15mar2020 "Swiss Lockdown (16.3.2020)", place(e) size(small) orient(horizontal) color(maroon))  ///
legend(order (8 "Japan" 9 "China" 10 "United Kingdom" 11 "Switzerland") cols(2))			///
scheme(s1color) 
graph export "${root}\figures\FIG6b_pmi_2020.png", replace
graph export "${root}\figures\FIG6b_pmi_2020.pdf", replace



********************************************************************************
*Konsumentenstimmung
********************************************************************************

import delimited "${root}\data\PMI_KS_Data\cons_dta_raw.csv", clear 

foreach var of varlist alsurv0002- cnsurv0052 cosurv1000- zasurv0018 {
	local var2 = substr("`var'", 1,2)
	rename `var' country_`var2'
}

foreach var of varlist cons2_cy_tot_cof_bs_m-cons2_ro_tot_cof_bs_m {
	local var2 = substr("`var'", 7,2)
	rename `var' country_`var2'
}


split time, parse("-")
destring time1, gen(year)
destring time2, gen(month)
destring time3, gen(day)

drop time*

gen date=mdy(month, day, year)
format date %tddd.nn.YY
sort date



foreach var of varlist country* {
	sum `var'
	gen `var'_std=(`var'-r(mean))/r(sd)
}

global TOP10 "country_de_std country_fr_std country_it_std country_at_std country_es_std country_gb_std country_us_std country_jp_std country_nl_std country_cn_std"

egen mean_top10=rowmean(${TOP10})
egen med_top10=rowmedian(${TOP10})
egen min_top10=rowmin(${TOP10})
egen max_top10=rowmax(${TOP10})

order date

twoway 	///
(line country_de_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin)) 	///
(line country_fr_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_it_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_at_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_es_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_us_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin)) ///
(line country_nl_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(gs12*0.5) lwidth(medthin))		///
(line country_jp_std date if date>=td(1jan2020) & date<td(1aug2020), lpattern(shortdash) lcolor(gs8) lwidth(medium))		///
(line country_cn_std date if date>=td(1jan2020) & date<td(1aug2020), lpattern(dash) lcolor(gs6) lwidth(medium)) 	///
(line country_gb_std date if date>=td(1jan2020) & date<td(1aug2020), lpattern(longdash) lcolor(gs2) lwidth(medium))	///
(line country_ch_std date if date>=td(1jan2020) & date<td(1aug2020), lcolor(maroon) lwidth(medium)),	///
ytitle("Standardized Consumer Confidence Index")  yscale(range (-5 3))  ///
ylabel(-5(1)3,nogrid) xlabel(#7)  xtitle("")									///
tline(16mar2020, lcolor(maroon) lwidth(medium)) 								///
yline(0, lcolor(gs0) lwidth(vthin)) 											///	
ttext(-5 15mar2020 "Swiss Lockdown (16.3.2020)", place(e) size(small) orient(horizontal) color(maroon))  ///
legend(order (8 "Japan" 9 "China" 10 "United Kingdom" 11 "Switzerland") cols(2))			///
scheme(s1color) 
graph export "${root}\figures\FIG6a_consco_2020.png", replace
graph export "${root}\figures\FIG6a_consco_2020.pdf", replace
